from selenium.webdriver.common.by import By
from selenium import webdriver
import time
import pytest
@pytest.fixture(scope='session')
def driver():
    driver=webdriver.Edge()
    driver.get('https://www.jiuxian.com/')
    driver.maximize_window()
    yield driver
    driver.quit()
def test_jiuxian(driver):
    try:
        # 点击请登录
        driver.find_element(By.XPATH,'/html/body/div[2]/div/div[1]/div/a[1]').click()
        time.sleep(2)
        # 断言账号登录
        dy1=driver.find_element(By.XPATH,'//*[@id="loginform"]/div/div/div/div/div[1]/div[1]/a[1]').text
        print(dy1)
        time.sleep(2)
        # 输入用户名和密码
        driver.find_element(By.NAME,'uname').send_keys('15336710135')
        driver.find_element(By.NAME,'_pwd').send_keys('002816Hj')
        time.sleep(10)
        # 点击登录
        driver.find_element(By.ID,'save').click()
        time.sleep(2)
        # 点击确定
        driver.find_element(By.CSS_SELECTOR,'.bindSub').click()
        time.sleep(2)
        # 输入搜索框
        driver.find_element(By.NAME,'key').send_keys('茅台')
        time.sleep(2)
        # 点击搜索按钮
        driver.find_element(By.XPATH,'//input[contains(@class,"search-btn")]').click()
        time.sleep(2)
    #     断言茅台
        dy2=driver.find_element(By.XPATH,'/html/body/div[6]/div/div[2]/div[1]/div[2]/a[2]').text
        assert "茅台" ==dy2
        print(dy2)
    except Exception as e:
        times=time.strftime('%Y%m%d_%H%M%S',time.localtime())
        return driver.save_screenshot('hj'+times+'.png')
